package com.example.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import com.example.pages.HomePage;

public class MovieProfilePage extends InternalPage {

	private static WebElement titleLink;

	@FindBy(linkText = "Edit")
	public WebElement editLink;

	@FindBy(xpath = "html/body/div[1]/div/div/section/nav/ul/li[2]/div/div/a")
	public WebElement seenLink;

	@FindBy(xpath = "html/body/div[1]/div/div/section/nav/ul/li[2]/div/div/a")
	public WebElement unseenLink;

	@FindBy(xpath = "html/body/div[1]/div/div/section/div/div[1]/div[2]/div[3]")
	public WebElement durationLink;

	@FindBy(xpath = "//h2")
	public WebElement title;

	public boolean isDurationFilmSaved(String minutes) {
		return durationLink.getText().contains(minutes);
	}

	public boolean isFilmProfilePageOpened(String movieName) {
		return title.getText().contains(movieName);
	}

	public static void clickOnMovieLink(String movieName) {
		int i = 0;
		for (i = 0; i < HomePage.linksToFilms.size(); i++) {
			if (HomePage.linksToFilms.get(i)
					.findElement(By.xpath("./div/div[2]")).getText()
					.equals(movieName))
				break;
		}
		titleLink = HomePage.linksToFilms.get(i);
		MovieProfilePage.titleLink.click();
	}

}
